/**
 * Created by liuzengrong on 2019/8/16.
 */
import React from 'react';
import { connect } from 'dva';
import { message } from 'antd';
import StandardModule from '@/components/hyperspace/modules/StandardModule';

/**
 * 自定义模块
 */
// @ts-ignore
const LocalModule: React.FC = ({ potential, dispatch }) => (
  <StandardModule
    data={potential.data}
    dictionary={[
      {
        name: 'username',
        desc: '用户名',
        dataType: 'string',
      },
    ]}
    config={{
      common: {
        formItemOptions: {
          username: {
            rules: [{ required: true, message: '该字段不能为空！' }],
          },
          mobile: {
            rules: [{ required: true, message: '该字段不能为空！' }],
          },
          channel: {
            rules: [{ required: true, message: '该字段不能为空！' }],
          },
          gender: {
            rules: [{ required: true, message: '该字段不能为空！' }],
            initialValue: '',
          },
        },
      },
      search: {
        fields: ['username', 'mobile'], // 查询条件
      },
      list: {
        url: '/api/potentialCustomer/query',
        fields: [
          'id',
          'username',
          'mobile',
          'channel',
          'gender',
          'city',
          'email',
          'openId',
          'creator',
          'creatTime',
        ], // 列表字段
        format: {
          gender: {
            render: (value: any) => {
              if (value === '1') {
                return '男';
              }
              return '女';
            },
          },
        },
        extensions: {
          operations: [
            (record: any) => (
              <a
                onClick={() => {
                  message.info(`扩展操作：${JSON.stringify(record)}`);
                }}
              >
                扩展操作
              </a>
            ),
          ],
        },
      },
      add: {
        url: '/api/potentialCustomer/create',
        // width: 680, // 非必填，默认680px
        // title: '新建表单', // 非必填，默认`新建`
        fields: ['username', 'mobile', 'channel', 'gender', 'country', 'province', 'city', 'email'], // 新增表单字段
      },
      update: {
        url: '/api/potentialCustomer/update',
        // width: 680, // 非必填，默认680px
        // title: '新建表单', // 非必填，默认`新建`
        fields: ['username', 'mobile', 'email', 'channel', 'gender', 'country', 'province', 'city'], // 修改表单字段
        primaryKeys: ['id'], // 主键字段列表
      },
      delete: {
        url: '/api/potentialCustomer/remove',
        batchDelete: false, // 是否开启批量删除
        fields: ['id'], // 删除依据字段
      },
    }}
    namespace="potential"
    dispatch={dispatch}
  />
);

// @ts-ignore
export default connect(({ potential }) => ({
  potential,
}))(LocalModule);
